"""
A股投资智能体系统 - 主入口
基于多智能体协同的投资决策系统
"""
import os
import logging
from loguru import logger
from pathlib import Path

# 导入配置
from config.settings import LOG_LEVEL

# 设置日志
logging_level = getattr(logging, LOG_LEVEL)
logger.remove()
logger.add(
    "logs/abot_{time:YYYY-MM-DD}.log",
    level=LOG_LEVEL,
    rotation="1 day",
    retention="30 days",
    format="{time:YYYY-MM-DD HH:mm:ss} | {level} | {message}"
)
logger.add(lambda msg: print(msg), level=LOG_LEVEL)

def main():
    """主程序入口点"""
    logger.info("启动A股投资智能体系统")
    
    # 确保目录存在
    Path("logs").mkdir(exist_ok=True)
    
    try:
        # 导入工作流
        from workflows.investment_team import create_investment_team
        
        # 创建并执行投资团队工作流
        investment_team = create_investment_team()
        
        # 启动团队工作
        investment_team.run()
        
    except Exception as e:
        logger.error(f"系统执行过程中发生错误: {e}")
        import traceback
        logger.error(traceback.format_exc())
    
    logger.info("A股投资智能体系统任务完成")

if __name__ == "__main__":
    main()